import request from '@/utils/request'
import type { ApiResponse, ApiListResponse } from '@/types/common'
import type { Lawfirm, Lawyer } from '@/types/lawyer'

// 律师管理相关API接口定义
export const lawyerApi = {
  // 获取律所列表
  getLawfirmList: (params: any): Promise<ApiListResponse<Lawfirm>> => {
    return request({
      url: '/api/lawyer/lawfirm/list',
      method: 'get',
      params,
    })
  },

  // 添加/编辑律所
  saveLawfirm: (data: any) => {
    return request({
      url: '/api/lawyer/lawfirm/add',
      method: 'post',
      data,
    })
  },

  // 删除律所
  deleteLawfirm: (data: any) => {
    return request({
      url: '/api/lawyer/lawfirm/delete',
      method: 'post',
      data,
    })
  },

  // 获取律师列表
  getLawyerList: (params: any): Promise<ApiResponse<Lawyer[]>> => {
    return request({
      url: '/api/lawyer/list',
      method: 'get',
      params,
    })
  },

  // 添加律师
  addLawyer: (data: any) => {
    return request({
      url: '/api/lawyer/add',
      method: 'post',
      data,
    })
  },

  // 编辑律师
  editLawyer: (data: any) => {
    return request({
      url: '/api/lawyer/edit',
      method: 'post',
      data,
    })
  },

  // 禁用/恢复律师账号
  setLawyerStatus: (data: any) => {
    return request({
      url: '/api/lawyer/lawyer/set',
      method: 'post',
      data,
    })
  },

  // 重置律师密码
  resetLawyerPassword: (data: any) => {
    return request({
      url: '/api/lawyer/lawyer/reset_psw',
      method: 'post',
      data,
    })
  },

  // 同步律师到用户系统
  syncLawyerToUser: (data: any): Promise<ApiResponse<any>> => {
    return request({
      url: '/api/lawyer/sync/sync_lawyer_to_user',
      method: 'post',
      data,
    })
  },

  // 批量同步律师
  batchSyncLawyers: (data: any): Promise<ApiResponse<any>> => {
    return request({
      url: '/api/lawyer/sync/batch_sync',
      method: 'post',
      data,
    })
  },

  // 获取可同步的律师列表
  getSyncableLawyers: (params: any): Promise<ApiResponse<Lawyer[]>> => {
    return request({
      url: '/api/lawyer/sync/get_syncable_lawyers',
      method: 'get',
      params,
    })
  },

  // 获取律所律师列表（用于案件管理）
  getLawFirmLawyers: (params: any): Promise<ApiResponse<Lawyer[]>> => {
    return request({
      url: '/api/lawyer/get_law_firm_lawyers',
      method: 'get',
      params,
    })
  },

  // 设置律师登录权限
  setLawyerLoginPermission: (data: any): Promise<ApiResponse<any>> => {
    return request({
      url: '/api/lawyer/lawyer/toggle_login_permission',
      method: 'post',
      data,
    })
  },
}
